package com.jxb.sort;

import java.util.Arrays;

/**
 * 冒泡排序
 */
public class BubbleSort {
    public static void main(String[] args) {
        int[] nums = {1,4,3,6,0,4,5,9,4,2,6};
        System.out.println("排序开始----------------->" + Arrays.toString(nums));
        sortArray(nums);
    }

    public static int[] sortArray(int[] nums) {
        if (nums.length ==0) {
            return nums;
        }
        //需要比较的次数
        for (int i = 0;i<nums.length;i++) {
            //前后比较，交换位置
            for (int j = 0;j<nums.length-1;j++) {
                if (nums[j+1] < nums[j]) {
                    int temp = nums[j+1];
                    nums[j+1] = nums[j];
                    nums[j] = temp;
                }
            }
            System.out.println(Arrays.toString(nums));
        }
        System.out.println("排序结束-------------->" + Arrays.toString(nums));
        return nums;
    }
}
